void main() {
  Person p = Person(name: "王皓");
  p.eat();

  // 直接用Teacher类声明
  Teacher t = Teacher(name: '马龙');
  t.eat();

  Student s = Student(name: "小趴菜");
  s.work();
}

class Person {
  String? name;
  int? age;
  String? sex;
  double? height;
  double? weight;
  String? hobby;

  //  同名
  Person({this.name, this.age, this.sex, this.hobby, this.height, this.weight});

  eat() {
    print('$name在吃饭');
  }

  sleep() {
    print('$name在睡觉');
  }

  run() {
    print('$name在跑步');
  }

  work() {
    print('$name在工作');
  }
}

// Teacher
class Teacher extends Person {
  // 继承父类构造函数
  // super 当前的父类构造函数对象
  Teacher(
      {String? name,
      int? age,
      String? sex,
      double? height,
      String? hobby,
      double? weight})
      : super(
            name: name, age: age, height: height, hobby: hobby, weight: weight);

  // 两部 第一步 接收teacher传递过来的参数
  // 调用父类的构造函数 把值传递过去
  @override
  eat() {
    // TODO: implement eat
    // return super.eat();
    print("老子叫$name, 老在喝早茶");
  }
}

// Student
class Student extends Person {
  Student(
      {String? name,
      int? age,
      String? sex,
      double? height,
      String? hobby,
      double? weight})
      : super(
            name: name, age: age, height: height, hobby: hobby, weight: weight);
  @override
  work() {
    // TODO: implement work
    super.work(); // 执行父类的方法
    print("$name工作完摸鱼"); // 执行自己的方法
  }
}
